package com.huyanqi.front.rest;

import com.huyanqi.core.Page;


/**
 * 
 * <p>Title: CommonUtils.java</p>
 * 
 * <p>Description: 设置分页信息工具类</p>
 * 
 * <p>Datetime: 2011-12-25 下午11:36:56</p>
 *
 * @company 成都映潮科技有限公司
 * 
 * @author <a href="mailto:liwei@sunsharp.cn">p.k.ripper</a>
 *
 */
public class CommonUtils{
    /**
     * 
     * @param page
     * @return PageRespObj
     */
    public static PageRespObj setPageInfoFromPwd(@SuppressWarnings("rawtypes") Page page ){
		int currentPage = 0;
		int onePageSize = 0;
		long totalResults = 0;
		int firstResult = 0 ; 
		int nextPage = 0 ; 
		int previousPage = 0 ; 
		long totalPage = 0 ; 
	
		if ( page !=null )
		{
		    currentPage = page.getPageNum();
		    onePageSize = page.getPageSize();
		    totalResults = page.getTotalCount();
		    firstResult = page.getFirst();
		    nextPage = page.getNextPage();
		    previousPage = page.getPrePage();
		    totalPage = page.getTotalPages();
		 
		    PageRespObj obj = new PageRespObj();
		    obj.setCurrentPage( currentPage );
		    obj.setPageSize( onePageSize );
		    obj.setTotalResults( totalResults );
		    obj.setFirstResult( firstResult );
		    obj.setNextPage( nextPage ) ;
		    obj.setPreviousPage( previousPage ) ;
		    obj.setTotalPage( totalPage ) ;
	
		    return obj;
		}else{
		    return null ;
		}
    }
}
